//
//  Main_ViewController.m
//  ChatOnLine
//
//  Created by 吴晗帅 on 16/8/9.
//  Copyright © 2016年 WWT. All rights reserved.
//

#import "Main_ViewController.h"
#import "Chat_CollectionViewCell.h"
#import "AddressBook_CollectionViewCell.h"
#import "Find_CollectionViewCell.h"
#import "Mine_CollectionViewCell.h"
#import "TabbarCollectionViewCell.h"
@interface Main_ViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
/** 大collectionView. */
@property (nonatomic, retain) Base_CollectionView *BigCollectionView;
/** tabbar collectionView. */
@property (nonatomic, retain) Base_CollectionView *TabBarCollectionView;
@end

@implementation Main_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self createBigCollectionView];
    [self createTabBarCollectionView];
}

#pragma mark - 大collectionView
- (void)createBigCollectionView
{
    UICollectionViewFlowLayout *bigLayout = [[UICollectionViewFlowLayout alloc] init];
    bigLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    bigLayout.minimumLineSpacing = 0;
    bigLayout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49);
    bigLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.BigCollectionView = [[Base_CollectionView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49) collectionViewLayout:bigLayout];
    self.BigCollectionView.pagingEnabled = YES;
    [self.view addSubview:self.BigCollectionView];
    self.BigCollectionView.delegate = self;
    self.BigCollectionView.dataSource = self;
    
    /** 注册. */
    [self.BigCollectionView registerClass:[Chat_CollectionViewCell class] forCellWithReuseIdentifier:@"Chat_CollectionViewCell"];
    [self.BigCollectionView registerClass:[AddressBook_CollectionViewCell class] forCellWithReuseIdentifier:@"AddressBook_CollectionViewCell"];
    [self.BigCollectionView registerClass:[Find_CollectionViewCell class] forCellWithReuseIdentifier:@"Find_CollectionViewCell"];
    [self.BigCollectionView registerClass:[Mine_CollectionViewCell class] forCellWithReuseIdentifier:@"Mine_CollectionViewCell"];
}
#pragma mark - 创建TabBarCollectionView
- (void)createTabBarCollectionView
{
    UICollectionViewFlowLayout *smallLayout = [[UICollectionViewFlowLayout alloc] init];
    smallLayout.itemSize = CGSizeMake(SCREEN_WIDTH / 4, 49);
    smallLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    smallLayout.minimumLineSpacing = 0;
    self.TabBarCollectionView = [[Base_CollectionView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 49, SCREEN_WIDTH, 49) collectionViewLayout:smallLayout];
    [self.view addSubview:self.TabBarCollectionView];
    self.TabBarCollectionView.delegate = self;
    self.TabBarCollectionView.dataSource = self;
    [self.TabBarCollectionView registerClass:[TabbarCollectionViewCell class] forCellWithReuseIdentifier:@"TabbarCollectionViewCell"];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (collectionView == self.BigCollectionView) {
        if (indexPath.row == 0) {
            Chat_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Chat_CollectionViewCell" forIndexPath:indexPath];
            cell.contentView.backgroundColor = [UIColor redColor];
            return cell;
        }
        else if (indexPath.row == 1)
        {
            AddressBook_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AddressBook_CollectionViewCell" forIndexPath:indexPath];
            cell.contentView.backgroundColor = [UIColor orangeColor];
            return cell;
        }
        else if (indexPath.row == 2)
        {
            Find_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Find_CollectionViewCell" forIndexPath:indexPath];
            cell.contentView.backgroundColor = [UIColor yellowColor];
            return cell;
        }
        else
        {
            Mine_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Mine_CollectionViewCell" forIndexPath:indexPath];
            cell.contentView.backgroundColor = [UIColor blueColor];
            return cell;
        }

    }
    else
    {
        TabbarCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TabbarCollectionViewCell" forIndexPath:indexPath];
        cell.contentView.backgroundColor = [UIColor cyanColor];
        return cell;
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
